using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace Tezzanator.Net.XNAGUI
{
    public class Gui : DrawableGameComponent
    {
        public Controls.BaseControl RootControl; 
        public bool InputWasCaught = false;

        private SpriteBatch spritebatch;
        public Texture2D Cursor;

        public Gui(Game game)
            : base(game)
        {
            RootControl = new Controls.BaseControl();
            RootControl.SetGui(this);
        }

        protected override void LoadContent()
        {
            RootControl.Position = Vector2.Zero;
            RootControl.Size = new Vector2(Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height);
            spritebatch = new SpriteBatch(Game.GraphicsDevice);
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            spritebatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
            RootControl.Draw(gameTime, spritebatch);

            if (Cursor != null)
            {
                MouseState ms = Mouse.GetState();
                spritebatch.Draw(Cursor, new Vector2(ms.X, ms.Y), Color.White);
            }

            spritebatch.End();
            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            InputWasCaught = false;
            RootControl.Update(gameTime);
            base.Update(gameTime);
        }
    }
}
